package com.unitech.test;

import java.sql.*;

public class JDBCDemo01 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
         //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接对象
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc_demo?useSSL=true&characterEncoding=utf-8", "root", "root");
        //3.获取执行者对象，用来执行sql语句
        Statement statement = connection.createStatement();
        //4.执行sql,获取结果集
         //int row = statement.executeUpdate("insert into user values ('1004','赵六')");
        ResultSet resultSet = statement.executeQuery("select * from user ");
        //5.处理结果集
       /* if (row>0){
            System.out.println("插入成功！");
        }*/
       while (resultSet.next()==true){
           System.out.println(resultSet.getInt("user_id")+"\t"+resultSet.getString("user_name"));
       }
        //6.关闭连接
        resultSet.close();
        statement.close();
        connection.close();


    }
}
